package com.example.universitylibraryback.entity;

import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;

@Data
public class Book {
    private String bookId;
    private String isbn;
    private String title;
    private String author;
    private BookType type; // 书籍类型
    private BookStatus status; // 书籍状态
    private Integer totalCopies; // 总册数
    private Integer availableCopies; // 可借册数
    private Double price; // 价格
    private LocalDate purchaseDate; // 购入日期
    
    // 保留原有字段以保持兼容性
    private String publisher;
    private Integer publicationYear;
    private BigDecimal priceOld;
    private String classificationNo;
    private Integer stock;
    private String roomLocation;
    private String shelfNumber;
    private String bookStatus; // 兼容原有字符串状态
    private String summary;
    private String coverImageUrl;
    private String recommendedTags;
    private Date createTime;
    
    // 类型转换方法，确保兼容性
    public void setBookStatus(String status) {
        this.bookStatus = status;
        // 根据字符串状态设置枚举状态
        switch(status) {
            case "可借":
                this.status = BookStatus.AVAILABLE;
                break;
            case "已借":
                this.status = BookStatus.BORROWED;
                break;
            case "已预约":
                this.status = BookStatus.RESERVED;
                break;
            case "维修中":
                this.status = BookStatus.UNDER_REPAIR;
                break;
            default:
                this.status = BookStatus.UNAVAILABLE;
        }
    }
    
    public enum BookType {
        GENERAL,    // 普通图书
        REFERENCE,  // 参考书（不可借）
        RARE        // 稀缺图书
    }
    
    public enum BookStatus {
        AVAILABLE,      // 可借阅
        BORROWED,       // 已借出
        RESERVED,       // 已预约
        UNDER_REPAIR,   // 维修中
        UNAVAILABLE     // 不可用
    }
}